package com.hao1st.service1.biz.distributedtx.service.impl;

import com.hao1st.service1.biz.distributedtx.service.UserService;
import com.hao1st.service1.dbmap.entities.UserInfo;
import com.hao1st.service1.dbmap.imapper.UserInfoMapper;
import io.seata.spring.annotation.GlobalTransactional;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserInfoMapper userInfoMapper;

    @GlobalTransactional(name = "demo-global-tx", rollbackFor = Exception.class)
    @Override
    public int insNewUser() {

        UserInfo ui = new UserInfo();
        ui.setId("0002");
        ui.setUsername("DistributedTXUser");
        ui.setPassword("123456");

        return userInfoMapper.insert(ui);
    }
}
